//
//  ShenHeProgressView.m
//  51易借
//
//  Created by apple on 2017/9/20.
//  Copyright © 2017年 张睿. All rights reserved.
//

#import "ShenHeProgressView.h"

@implementation ShenHeProgressView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(void)awakeFromNib
{
    [super awakeFromNib];
    [self.stateBtns enumerateObjectsUsingBlock:^(UIButton * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj.titleLabel setFont:[UIFont systemFontOfSize:12*SCREENH6]];
    }];
    [self.stateLabels enumerateObjectsUsingBlock:^(UILabel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj setFont:[UIFont systemFontOfSize:12*SCREENH6]];
    }];


}
-(void)setModel:(BorrowDetailModel *)model
{
    _model = model;
    switch ([model.unionStatus integerValue]) {
        case 1:
        {
            [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [obj setHidden:NO];
            }];
            NSArray* statusTitles = @[@"申请成功",@"审核中",@"打款"];
            NSArray* titleSelected = @[@(YES),@(YES),@(NO)];
            NSArray* statueLabels = @[@"",@"正在审核，预计需要10分钟，请稍等",@""];
            for(int i = 0 ; i < 3 ; i++)
            {
                UIButton * button = self.stateBtns[i];
                UIImageView * icon = self.progressIcons[i];
                UILabel * label = self.stateLabels[i];
                button.selected = [titleSelected[i] boolValue];
                [button setTitle:statusTitles[i] forState:UIControlStateNormal];
                label.text = statueLabels[i];
                icon.highlighted = button.selected;
            }
            self.progressLines.backgroundColor = [[titleSelected lastObject] boolValue]?TOTAL_COLOR:self.myLabel.textColor;
        }
            break;
        case 2:
        {
            [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [obj setHidden:NO];
            }];
            
            NSArray* statusTitles = @[@"申请成功",@"审核未通过",@"打款"];
            NSArray* titleSelected = @[@(YES),@(YES),@(NO)];
            NSArray* statueLabels = @[@"",[NSString stringWithFormat:@"可再次申请日期 %@",[Lahelper formattedTimeFromTimeInterval:[model.loanTime longLongValue]]],@""];
            for(int i = 0 ; i < 3 ; i++)
            {
                UIButton * button = self.stateBtns[i];
                UIImageView * icon = self.progressIcons[i];
                UILabel * label = self.stateLabels[i];
                button.selected = [titleSelected[i] boolValue];
                [button setTitle:statusTitles[i] forState:UIControlStateNormal];
                label.text = statueLabels[i];
                icon.highlighted = button.selected;
            }
            self.progressLines.backgroundColor = [[titleSelected lastObject] boolValue]?TOTAL_COLOR:self.myLabel.textColor;
        }
            break;
        case 3:
        {
            [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [obj setHidden:NO];
            }];
            NSArray* statusTitles = @[@"申请成功",@"审核成功",@"打款中"];
            NSArray* titleSelected = @[@(YES),@(YES),@(YES)];
            NSArray* statueLabels = @[@"",@"",@"正在打款，预计需要10分钟，请稍等"];
            for(int i = 0 ; i < 3 ; i++)
            {
                UIButton * button = self.stateBtns[i];
                UIImageView * icon = self.progressIcons[i];
                UILabel * label = self.stateLabels[i];
                button.selected = [titleSelected[i] boolValue];
                [button setTitle:statusTitles[i] forState:UIControlStateNormal];
                label.text = statueLabels[i];
                icon.highlighted = button.selected;
            }
            self.progressLines.backgroundColor = [[titleSelected lastObject] boolValue]?TOTAL_COLOR:self.myLabel.textColor;
        }
            break;
        case 6:
        {
            [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [obj setHidden:NO];
            }];
            NSArray* statusTitles = @[@"主动还款",@"还款处理中",@"已结清"];
            NSArray* titleSelected = @[@(YES),@(YES),@(NO)];
            NSArray* statueLabels = @[@"",@"正在处理，预计需要10分钟，请稍等",@""];
            for(int i = 0 ; i < 3 ; i++)
            {
                UIButton * button = self.stateBtns[i];
                UIImageView * icon = self.progressIcons[i];
                UILabel * label = self.stateLabels[i];
                button.selected = [titleSelected[i] boolValue];
                [button setTitle:statusTitles[i] forState:UIControlStateNormal];
                label.text = statueLabels[i];
                icon.highlighted = button.selected;
            }
            self.progressLines.backgroundColor = [[titleSelected lastObject] boolValue]?TOTAL_COLOR:self.myLabel.textColor;
        }
            break;
        default:
        {
            [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [obj setHidden:YES];
            }];
        }
            break;
    }
}


-(UIImage *)imageWithColor:(UIColor *)color{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}
@end
